package com.wxq.product.controller;

import java.util.Arrays;
import java.util.Map;


//import com.wxq.product.interceptor.MyMvcConfig;
import com.wxq.product.vo.AttrVo;
import com.wxq.product.service.AttrService;
import com.wxq.product.vo.AttrVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.wxq.common.utils.PageUtils;
import com.wxq.common.utils.R;



/**
 * 商品属性
 *
 * @author jim
 * @email 2982877319@qq.com
 * @date 2022-03-13 19:57:58
 */
@RestController
@RequestMapping("product/attr")
public class AttrController {
    @Autowired
    private AttrService attrService;



    /**
     *
     * @param params
     * @param catelogId
     * @param attrType
     * @return
     */
    @GetMapping("/{attrType}/list/{catelogId}")
    public R listAtrr(@RequestParam Map<String, Object> params,
                      @PathVariable("catelogId") Long catelogId,
                      @PathVariable("attrType") String attrType){
        PageUtils page = attrService.queryBaseAttrPage(params,catelogId,attrType);
        return R.ok().put("page",page);
    }
    /**
     * 列表
     */
    @RequestMapping("/list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = attrService.queryPage(params);

        return R.ok().put("page", page);
    }

//    @RequestMapping("/change")
//    public void change(){
//        MyMvcConfig.myInterceptor.setState(true);
//        System.err.println("状态修改成功");
//    }


    /**
     * 信息
     */
    @RequestMapping("/info/{attrId}")
    public R info(@PathVariable("attrId") Long attrId){
		AttrVo attrV0 = attrService.getAttrInfo(attrId);

        return R.ok().put("attr", attrV0);
    }

    /**
     * 保存规格参数
     */
    @RequestMapping("/save")
    public R save(@RequestBody AttrVo attr){
		attrService.saveAttr(attr);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public R update(@RequestBody AttrVo attrV0){
		attrService.updateAttr(attrV0);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    public R delete(@RequestBody Long[] attrIds){
		attrService.removeByIds(Arrays.asList(attrIds));

        return R.ok();
    }

}
